package o;

import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.metadata.Metadata;
import java.util.Arrays;

public final class ahk extends aay implements Callback {
    private ahd ʻ;
    private int ʼ;
    private final long[] ʽ;
    private final abk ˊ;
    private boolean ˊॱ;
    private final ahg ˋ;
    @Nullable
    private final Handler ˎ;
    private final ahh ˏ;
    private final ahj ॱ;
    private int ॱॱ;
    private final Metadata[] ᐝ;

    public ahk(ahh o_ahh, @Nullable Looper looper) {
        this(o_ahh, looper, ahj.ˋ);
    }

    public ahk(ahh o_ahh, @Nullable Looper looper, ahj o_ahj) {
        Handler handler;
        super(4);
        this.ˏ = (ahh) amm.ॱ(o_ahh);
        if (looper == null) {
            handler = null;
        } else {
            handler = anr.ˏ(looper, (Callback) this);
        }
        this.ˎ = handler;
        this.ॱ = (ahj) amm.ॱ(o_ahj);
        this.ˊ = new abk();
        this.ˋ = new ahg();
        this.ᐝ = new Metadata[5];
        this.ʽ = new long[5];
    }

    public int ˎ(Format format) {
        if (this.ॱ.ˊ(format)) {
            return aay.ˎ(null, format.ʻ) ? 4 : 2;
        } else {
            return 0;
        }
    }

    public void ˏ(Format[] formatArr, long j) throws ExoPlaybackException {
        this.ʻ = this.ॱ.ˏ(formatArr[0]);
    }

    public void ˏ(long j, boolean z) {
        ʼॱ();
        this.ˊॱ = false;
    }

    public void ˊ(long j, long j2) throws ExoPlaybackException {
        if (!this.ˊॱ && this.ॱॱ < 5) {
            this.ˋ.ˊ();
            if (ˊ(this.ˊ, this.ˋ, false) == -4) {
                if (this.ˋ.ˏ()) {
                    this.ˊॱ = true;
                } else if (!this.ˋ.i_()) {
                    this.ˋ.ˊ = this.ˊ.ॱ.ˊॱ;
                    this.ˋ.ᐝ();
                    int i = (this.ʼ + this.ॱॱ) % 5;
                    Metadata ˊ = this.ʻ.ˊ(this.ˋ);
                    if (ˊ != null) {
                        this.ᐝ[i] = ˊ;
                        this.ʽ[i] = this.ˋ.ˏ;
                        this.ॱॱ++;
                    }
                }
            }
        }
        if (this.ॱॱ > 0 && this.ʽ[this.ʼ] <= j) {
            ˎ(this.ᐝ[this.ʼ]);
            this.ᐝ[this.ʼ] = null;
            this.ʼ = (this.ʼ + 1) % 5;
            this.ॱॱ--;
        }
    }

    public void ॱˎ() {
        ʼॱ();
        this.ʻ = null;
    }

    public boolean ʽॱ() {
        return this.ˊॱ;
    }

    public boolean ˈ() {
        return true;
    }

    private void ˎ(Metadata metadata) {
        if (this.ˎ != null) {
            this.ˎ.obtainMessage(0, metadata).sendToTarget();
        } else {
            ˋ(metadata);
        }
    }

    private void ʼॱ() {
        Arrays.fill(this.ᐝ, null);
        this.ʼ = 0;
        this.ॱॱ = 0;
    }

    public boolean handleMessage(Message message) {
        switch (message.what) {
            case 0:
                ˋ((Metadata) message.obj);
                return true;
            default:
                throw new IllegalStateException();
        }
    }

    private void ˋ(Metadata metadata) {
        this.ˏ.ˋ(metadata);
    }
}
